<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
class Contactus extends Base{
    public function message()
    {
        if(!empty(input("param.name"))){
            $data['name']=input("param.name");
        }else{
            return json(['code' => 501, 'msg' => '请输入姓名']);
        }
        if(!empty(input("param.tel"))){
            $data['tel']=input("param.tel");
        }else{
            return json(['code' => 502, 'msg' => '请输入电话']);
        }
        if(!empty(input("param.email"))){
            $data['email']=input("param.email");
        }else{
            return json(['code' => 503, 'msg' => '请输入邮箱']);
        }
        if(!empty(input("param.company"))){
            $data['company']=input("param.company");
        }else{
            return json(['code' => 504, 'msg' => '请输入公司']);
        }
        if(!empty(input("param.message"))){
            $data['message']=input("param.message");
        }
        $data['time']=time();
        $data['ip']=$_SERVER["REMOTE_ADDR"];
        $exit=Db::name('message')->where('time','>',time()-60)->where('ip',$data['ip'])->order('id desc')->find();
        if($exit){
            return json(['code' => 505, 'msg' => '提交过于频繁']);
        }
        $res=Db::name('message')->insert($data);
        if($res){
            return json(['code' => 200, 'msg' => '提交成功']);
        }else{
            return json(['code' => 500, 'msg' => '提交失败']);
        }
    }
    public function resume()
    {
        if(!empty(input("param.name"))){
            $data['name']=input("param.name");
        }else{
            return json(['code' => 501, 'msg' => '请输入姓名']);
        }
        if(!empty(input("param.sex"))){
            $data['sex']=input("param.sex");
        }else{
            return json(['code' => 502, 'msg' => '请选择性别']);
        }
        if(!empty(input("param.marry"))){
            $data['marry']=input("param.marry");
        }
        if(!empty(input("param.birthday"))){
            $data['birthday']=input("param.birthday");
        }else{
            return json(['code' => 503, 'msg' => '请输入出生年月']);
        }
        if(!empty(input("param.health"))){
            $data['health']=input("param.health");
        }
        if(!empty(input("param.email"))){
            $data['email']=input("param.email");
        }
        if(!empty(input("param.phone"))){
            $data['phone']=input("param.phone");
        }else{
            return json(['code' => 504, 'msg' => '请输入手机号']);
        }
        if(!empty(input("param.live_address"))){
            $data['live_address']=input("param.live_address");
        }else{
            return json(['code' => 505, 'msg' => '请输入住址']);
        }
        if(!empty(input("param.record"))){
            $data['record']=input("param.record");
        }else{
            return json(['code' => 506, 'msg' => '请输入学历']);
        }
        if(!empty(input("param.work_age"))){
            $data['work_age']=input("param.work_age");
        }else{
            return json(['code' => 507, 'msg' => '请输入工作年限']);
        }
        if(!empty(input("param.hope_salary"))){
            $data['hope_salary']=input("param.hope_salary");
        }
        if(!empty(input("param.job"))){
            $data['job']=input("param.job");
        }else{
            return json(['code' => 508, 'msg' => '请输入职位']);
        }
        if(!empty(input("param.will_work_time"))){
            $data['will_work_time']=input("param.will_work_time");
        }else{
            return json(['code' => 509, 'msg' => '请输入预计到岗时间']);
        }
        if(!empty(input("param.message"))){
            $data['message']=input("param.message");
        }
        if(!empty(input("param.cv"))){
            $data['cv']=input("param.cv");
        }
        $data['time']=time();
        $data['uptime']=time();
        $data['ip']=$_SERVER["REMOTE_ADDR"];
        $exit=Db::name('resume')->where('time','>',time()-60)->where('ip',$data['ip'])->order('id desc')->find();
        if($exit){
            return json(['code' => 505, 'msg' => '提交过于频繁']);
        }
        $res=Db::name('resume')->insert($data);
        if($res){
            return json(['code' => 200, 'msg' => '提交成功']);
        }else{
            return json(['code' => 500, 'msg' => '提交失败']);
        }
    }
    
    
}